package net.chrisrichardson.ormunit;

import java.util.HashSet;
import java.util.Set;

/**
 * Helper class for constructing sets of class.fieldNames to ignore
 * 
 * @author cer
 * 
 */

public class PropertyNameSet {

	private Set<String> fields = new HashSet<String>();

	private Class lastType;

	public PropertyNameSet(Class type, String field) {
		add(type, field);
	}

	public PropertyNameSet(String fieldName) {
		add(fieldName);
	}

	public PropertyNameSet add(Class type, String field) {
		if (type == null) {
			fields.add(field);
		} else {
			this.lastType = type;
			fields.add(type.getName() + "." + field);
		}
		return this;
	}

	public PropertyNameSet add(String field) {
		add(lastType, field);
		return this;
	}

	public Set<String> asSet() {
		return fields;
	}

	public PropertyNameSet and(String fieldName) {
		return add(fieldName);
	}

	public PropertyNameSet and(Class type, String fieldName) {
		return add(type, fieldName);
	}

	public static PropertyNameSet except(String fieldName) {
		return new PropertyNameSet(fieldName);
	}

	public static PropertyNameSet except(Class type, String name) {
		return new PropertyNameSet(type, name);
	}

	public static PropertyNameSet makePropertyNameSet(Class type, String field) {
		return new PropertyNameSet(type, field);
	}


}
